package com.yihu.cms.service;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yihu.beans.ps.FilePath;
import com.yihu.cms.action.ArticleController;
import com.yihu.dataService.hessian.mongodb.interfaceService.FilePathHService;
import com.yihu.dataService.hessian.resource.ResourceMongoDBManager;

public class FilePathService {
	
	private final Logger log = LoggerFactory.getLogger(ArticleController.class); 
	
	public List<FilePath> getFilePathList() {
//		FilePath fi = null;
//		try {
//			FilePathHService filePathS = (FilePathHService) ResourceMongoDBManager
//					.getSingleton().getBeans("filePathHSC");
//			fi = filePathS.addFilePath(filePath);
//		} catch (MalformedURLException e) {
//			log.error("FilePathService.add MalformedURLException . error=" + e.toString());
//		} catch (IOException e1) {
//			log.error("FilePathService.add error=" + e1.toString());
//		}
		return null;
	}

	public FilePath add(FilePath filePath) {
		FilePath fi = null;
		try {
			FilePathHService filePathS = (FilePathHService) ResourceMongoDBManager
					.getSingleton().getBeans("filePathHSC");
			fi = filePathS.addFilePath(filePath);
		} catch (MalformedURLException e) {
			log.error("FilePathService.add MalformedURLException . error=" + e.toString());
		} catch (IOException e1) {
			log.error("FilePathService.add error=" + e1.toString());
		}
		return fi;
	}

	public FilePath del(String id) {
		FilePath result = null;
		try {
			FilePathHService filePathS = (FilePathHService) ResourceMongoDBManager
					.getSingleton().getBeans("filePathHSC");
			result = filePathS.delFilePath(id);
		} catch (MalformedURLException e) {
			log.error("FilePathService.add MalformedURLException . error=" + e.toString());
//			result = 1;
		} catch (IOException e1) {
			log.error("FilePathService.add error=" + e1.toString());
//			result = 2;
		}
		return result;
	}
	
	public FilePath getById(String id) {
		FilePath fi = null;
		try {
			FilePathHService filePathS = (FilePathHService) ResourceMongoDBManager
					.getSingleton().getBeans("filePathHSC");
			fi = filePathS.getFilePathById(id);
		} catch (MalformedURLException e) {
			log.error("FilePathService.add MalformedURLException . error=" + e.toString());
		} catch (IOException e1) {
			log.error("FilePathService.add error=" + e1.toString());
		}
		return fi;
	}
	
}
